package cn.edu.scau.cmi.chenxiaoqin.hibernate.factory;

import cn.edu.scau.cmi.chenxiaoqin.hibernate.domain.*;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;
import org.hibernate.service.ServiceRegistry;
import org.hibernate.service.ServiceRegistryBuilder;

import cn.edu.scau.cmi.chenxiaoqin.hibernate.domain.Student;

public class HibernateSessionFactory {
    private static SessionFactory sessionFactory;
    private static Session session;
    static {
    	Configuration configuration=new Configuration().configure();
    	ServiceRegistry sr=new ServiceRegistryBuilder().applySettings(configuration.getProperties()).buildServiceRegistry();
    	sessionFactory=configuration.buildSessionFactory(sr);
    }
    
    public static Session getSession() {
    	session=sessionFactory.openSession();
    	return session;
    }
}
